﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using com.codebump;
using System.Security.Cryptography;




public partial class Sebaclear_Sebaclear : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            if (Request.QueryString.HasKeys())
            {
                if (Request.QueryString["listid"] != String.Empty)
                    Session["listid"] = Request.QueryString["listid"];
                else
                    Session["listid"] = 1;


                if (Request.QueryString["dnis"] != null)
                {
                    Session["dnis"] = Request.QueryString["dnis"];
                }
                else
                {
                    Session["dnis"] = "9999999999";
                }

                Session["servername"] = Request.QueryString["servername"];
                Session["projectname"] = Request.QueryString["projectname"];
                Session["campaignname"] = Request.QueryString["campaignname"];
                Session["agentid"] = Request.QueryString["agentid"];
                Session["agentfirst"] = Request.QueryString["agentfirst"];
                Session["agentlast"] = Request.QueryString["agentlast"];


                Session["App"] = new DataAccess();
            }

            ((DataAccess)Session["App"]).PutCallData("webtransfer", "8882785115");
            SaveOriginalCallinfo(((DataAccess)Session["App"]).GetCallData("ANI"));

            lblAgentName.Text = (Session["agentfirst"].ToString() + " " + Session["agentlast"].ToString()).Trim();
        
        }

    }


    //POST LOGIC - For Step or Start pages
    //Add if statements as you add pages
    //For Next and Finish pages it is best to use the index in the if statements as below
    protected void WebWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {

        int page = WebWizard.ActiveStepIndex;
        if (page == WebWizard.WizardSteps.IndexOf(this.Intro))
        {
            return;
        }

        if (page == WebWizard.WizardSteps.IndexOf(this.SebaclearPitch))
        {
            lblOfferAMC.ForeColor = System.Drawing.Color.Red;
            lblOfferTAC.ForeColor = System.Drawing.Color.Red;
            lblOfferTAC2.ForeColor = System.Drawing.Color.Red;
            lblOfferAMCReb.ForeColor = System.Drawing.Color.Red;

            //This Switch is a sample only Please modify or delete as needed.
            if (cbFreeOffer.Checked)// free offer
            {
                lblOfferAMC.Text = "$6.99 ($8.99 Canada) shipping and handling";
                lblOfferTAC.Text = "$26.94";
                lblOfferTAC2.Text = "$26.94";
                lblOfferAMCReb.Text = "$6.99 ($8.99 Canada) shipping and handling";


                ddlProducts.Items.Clear();
                ddlProducts.Items.Add(new ListItem("Choose One", "0"));
                ddlProducts.Items.Add(new ListItem("FREE SEBACLEAR CONTINUITY", "1"));
                ddlProducts.Items.Add(new ListItem("FREE SEBACLEAR + DAY CREME (BOTH CONTINUITY)", "2"));
                ddlProducts.Items.Add(new ListItem("FREE SEBACLEAR CONTINUITY + DAY CREME ONE TIME", "3"));
            }
            else// paid offer
            {
                lblOfferAMC.Text = "$39.95 plus $6.99 ($8.99 Canada) shipping and handling";
                lblOfferTAC.Text = "$66.89";
                lblOfferTAC2.Text = "$66.89";
                lblOfferAMCReb.Text = "$39.95 plus $6.99 ($8.99 Canada) shipping and handling";

                ddlProducts.Items.Clear();
                ddlProducts.Items.Add(new ListItem("Choose One", "0"));
                ddlProducts.Items.Add(new ListItem("SEBACLEAR ONE TIME", "4"));
                ddlProducts.Items.Add(new ListItem("SEBACLEAR CONTINUITY", "5"));
                ddlProducts.Items.Add(new ListItem("SEBACLEAR + DAY CREME (BOTH ONE TIME)", "6"));
                ddlProducts.Items.Add(new ListItem("SEBACLEAR + DAY CREME (BOTH CONTINUITY)", "7"));
                ddlProducts.Items.Add(new ListItem("SEBACLEAR CONTINUITY + DAY CREME ONE TIME", "8"));
            }
            ddlProducts.Items[0].Selected = true;
            return;

        }

        if (page == WebWizard.WizardSteps.IndexOf(this.ConfirmOrder))
        {
            //if (lblCustDataEntered.Visible)
            //{
            //    //var nextbutton = WebWizard.FindControl("StepNavigationTemplateContainerID").FindControl("StepNextButton") as LinkButton;
            //    ((LinkButton)WebWizard.FindControl("StepNavigationTemplateContainerID").FindControl("StepNextButton")).Visible = false;
            //    return;
            //}
            //else
            //{
            //    //var nextbutton = WebWizard.FindControl("StepNavigationTemplateContainerID").FindControl("StepNextButton") as LinkButton;
            //    ((LinkButton)WebWizard.FindControl("StepNavigationTemplateContainerID").FindControl("StepNextButton")).Visible = true;
            //}



            //if (ddlProducts.SelectedItem.Text == "Choose One" && ddlProducts.Visible)
            //{
            //    lblNoProduct.Visible = true;
            //    return;
            //}
            //else
            //{
            //    lblNoProduct.Visible = false;
            //    //((DataAccess)Session["App"]).PutCallData("webusercode", "N0");
            //    //WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
            //    return;
            //}
            
            
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
        {
            return;
        }



    }

    //POST LOGIC for disposition pages
    //this is for pages that contain a disposition button
    protected void WebWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {

        int page = WebWizard.ActiveStepIndex;
        if (page == WebWizard.WizardSteps.IndexOf(this.Intro))
        {
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.SebaclearPitch))
        {
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Preauth))
        {
            //Change These two lines of code - For Information Only

            //((DataAccess)Session["App"]).PutCallData("webusercode", "N0");
            //WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
        {
            return;
        }


    }

    //PRE-LOGIC
    //Add if statements as needed for post-logic
    //You can use the Step ID name instead of the index as used in Next and Finish logic.
    protected void WebWizard_ActiveStepChanged(object sender, EventArgs e)
    {


        if (WebWizard.ActiveStep.Title.ToString() == "Disposition")
        {
            //These two lines should be fairly standard - they write the in-memory tables to the Database
            DispoDDL1.Visible = false;
            ((DataAccess)Session["App"]).PutCallData("webusercode", "N0");
            ((DataAccess)Session["App"]).CommitCallData();

            foreach (System.Data.DataRow r in ((DataAccess)Session["App"]).GetProducts().Rows)
            {
                ((DataAccess)Session["App"]).RemoveOrderItem(Convert.ToInt32(r["productid"]));
            }

            //((DataAccess)Session["App"]).PutOrderItem(Convert.ToInt32(ddlProducts.SelectedValue) ,1);
            AddProducts();
            ((DataAccess)Session["App"]).CommitOrder();
        }

        if (WebWizard.ActiveStep.Title.ToString() == "Preauth")
        {
            if (ddlProducts.SelectedIndex == 0)
            {
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.ConfirmOrder);
                return;
            }

            DispoDDL1.Visible = true;

            ((DataAccess)Session["App"]).PutCallData("webusercode", "");
            ((DataAccess)Session["App"]).CommitCallData();

            foreach (System.Data.DataRow r in ((DataAccess)Session["App"]).GetProducts().Rows)
            {
                ((DataAccess)Session["App"]).RemoveOrderItem(Convert.ToInt32(r["productid"]));
            }
            ((DataAccess)Session["App"]).CommitOrder();


            //double SH = 0;
            //if (ddlCountry.SelectedItem.Text == "CANADA")
            //{
            //    SH = 8.99;
            //}
            //else
            //{
            //    SH = 6.99;
            //}

            //switch(ddlProducts.SelectedValue)
            //{
            //    case "162":
            //        lblAmount.Text = Convert.ToString(SH + 29.95);
            //        break;
            //    case "163":
            //        lblAmount.Text = Convert.ToString(SH);
            //        break;
            //    case "164":
            //        lblAmount.Text = Convert.ToString(SH + 29.95);
            //        break;
            //    case "165":
            //        lblAmount.Text = Convert.ToString(SH);
            //        break;
            //    case "166":
            //        lblAmount.Text = Convert.ToString(19.95);
            //        break;
            //    case "167":
            //        lblAmount.Text = Convert.ToString(SH + 19.95 + 29.95);
            //        break;
            //    case "168":
            //        lblAmount.Text = Convert.ToString(SH + 19.95);
            //        break;
            //    default:
            //        break;
            //}
            
        }

    }
    protected void btnReb1_Click(object sender, EventArgs e)
    {
        pnlReb1.Visible = !pnlReb1.Visible;
    }

    protected void btnNo30Days_Click(object sender, EventArgs e)
    {

        pnlNo30Days.Visible = !pnlNo30Days.Visible;
    }
    protected void btnSubmit_Click(object sender, System.EventArgs e)
    {
        lblError.Text = "";

        bool bCustValid = false;
        bool ccCheck = false;
        bool ecCheck = false;
        bool bShipValid = false;

        int result;

        bCustValid = !(string.IsNullOrEmpty(tbFirstName.Text) ||
            string.IsNullOrEmpty(tbLastName.Text) ||
            string.IsNullOrEmpty(tbAddr.Text) ||
            //string.IsNullOrEmpty(tbAddr2.Text) ||
            string.IsNullOrEmpty(tbZip.Text) ||
            string.IsNullOrEmpty(ddlCity.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlState.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlCountry.SelectedItem.Text)) &&
            (ddlCity.SelectedIndex > 0);


        ccCheck = !(string.IsNullOrEmpty(ddlCardType.SelectedItem.Text) ||
            string.IsNullOrEmpty(tbCCNumber.Text) ||
            string.IsNullOrEmpty(tbCCV.Text) ||
            string.IsNullOrEmpty(tbExpDate.Text)) &&
            (((DataAccess)Session["App"]).IsValidCC(GetCardType(ddlCardType.SelectedValue), tbCCNumber.Text)) &&
            (Int32.TryParse(tbCCV.Text, out result)) &&
            (Int32.TryParse(tbExpDate.Text, out result)) &&
            (tbExpDate.Text.Length == 4);



        ecCheck = !(string.IsNullOrEmpty(tbBankName.Text) ||
            string.IsNullOrEmpty(tbAccNum.Text) ||
            string.IsNullOrEmpty(tbRoutNum.Text) ||
            string.IsNullOrEmpty(tbBankCity.Text) ||
            string.IsNullOrEmpty(tbCheckNum.Text)) &&
            (Int32.TryParse(tbAccNum.Text, out result)) &&
            (Int32.TryParse(tbRoutNum.Text, out result)) &&
            (Int32.TryParse(tbCheckNum.Text, out result));

        bShipValid = !(string.IsNullOrEmpty(tbShipAddr.Text) ||
            //string.IsNullOrEmpty(tbShipaddr2.Text) ||
            string.IsNullOrEmpty(tbShipZip.Text) ||
            string.IsNullOrEmpty(ddlShipCity.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlShipState.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlShipCountry.SelectedItem.Text)) &&
            (ddlShipCity.SelectedIndex > 0) &&
            (tbShipZip.Text.Length >= 5) &&
            (tbShipZip.Text.Length <= 7);



        if (bCustValid)
        {
            ((DataAccess)Session["App"]).PutCallData("firstname", tbFirstName.Text);
            ((DataAccess)Session["App"]).PutCallData("lastname", tbLastName.Text);
            ((DataAccess)Session["App"]).PutCallData("address1", tbAddr.Text);
            if (!string.IsNullOrEmpty(tbAddr2.Text))
                ((DataAccess)Session["App"]).PutCallData("address2", tbAddr2.Text);
            else
                ((DataAccess)Session["App"]).PutCallData("address2", "");
            ((DataAccess)Session["App"]).PutCallData("Zip", tbZip.Text);
            ((DataAccess)Session["App"]).PutCallData("City", ddlCity.SelectedItem.Text);
            ((DataAccess)Session["App"]).PutCallData("State", ddlState.SelectedItem.Text);
            ((DataAccess)Session["App"]).PutCallData("Country", ddlCountry.SelectedItem.Text);

            if (!cbShipping.Checked)
            {
                //((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbAddr.Text);
                //if (!string.IsNullOrEmpty(tbAddr2.Text))
                //    ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbAddr2.Text);
                //else
                //    ((DataAccess)Session["App"]).PutCallData("ShipAddress2", "");
                //((DataAccess)Session["App"]).PutCallData("ShipZip", tbZip.Text);
                //((DataAccess)Session["App"]).PutCallData("ShipCity", ddlCity.SelectedItem.Text);
                //((DataAccess)Session["App"]).PutCallData("ShipState", ddlState.SelectedItem.Text);
                //((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlCountry.SelectedItem.Text);
            }
            else
            {
                if (bShipValid)
                {
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbShipAddr.Text);
                    if (!string.IsNullOrEmpty(tbShipAddr.Text))
                        ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbShipaddr2.Text);
                    else
                        ((DataAccess)Session["App"]).PutCallData("ShipAddress2", "");
                    ((DataAccess)Session["App"]).PutCallData("ShipZip", tbShipZip.Text);
                    ((DataAccess)Session["App"]).PutCallData("ShipCity", ddlShipCity.SelectedItem.Text);
                    ((DataAccess)Session["App"]).PutCallData("ShipState", ddlShipState.SelectedItem.Text);
                    ((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlShipCountry.SelectedItem.Text);
                }
                else
                {
                    lblError.Text += "Enter Shipping Info<br/>";
                }
            }
        }
        else
        {
            if (ddlCity.SelectedIndex == 0)
                lblError.Text += "Select a City<br/>";
            else
                lblError.Text += "Enter Valid Customer Data<br/>";
        }

        if ((!string.IsNullOrEmpty(tbPhone.Text)) && ((tbPhone.Text.Length != 10) || !(System.Text.RegularExpressions.Regex.Match(tbPhone.Text, @"^[1-9]\d{2}[1-9]\d{6}$").Success)))
        {
            lblError.Text += "Invalid Phone<br/>";
        }
        else
        {
            if (!string.IsNullOrEmpty(tbPhone.Text))
                ((DataAccess)Session["App"]).PutCallData("PrimaryPhone", tbPhone.Text);
        }

        if ((!string.IsNullOrEmpty(tbEmail.Text)) && !((DataAccess)Session["App"]).IsValidEmail(tbEmail.Text))
        {
            lblError.Text += "Invalid Email<br/>";
        }
        else
        {
            if (!string.IsNullOrEmpty(tbEmail.Text))
                ((DataAccess)Session["App"]).PutCallData("Email", tbEmail.Text);
        }





        if (ddlPaymentType.SelectedIndex == 1) // debit/credit
        {
            ((DataAccess)Session["App"]).PutCallData("PaymentType", ddlPaymentType.SelectedItem.Value);

            if (ccCheck)
            {
                ((DataAccess)Session["App"]).PutCallData("CCType", ddlCardType.SelectedItem.Value);
                ((DataAccess)Session["App"]).PutCallData("CCNumber", ((DataAccess)Session["App"]).EnryptData(tbCCNumber.Text));
                ((DataAccess)Session["App"]).PutCallData("CCV", ((DataAccess)Session["App"]).EnryptData(tbCCV.Text));
                ((DataAccess)Session["App"]).PutCallData("CCExpDate", tbExpDate.Text);
            }
            else
            {
                lblError.Text += "Invalid Card Info<br/>";
            }
        }
        else if (ddlPaymentType.SelectedIndex == 2) // echeck
        {
            ((DataAccess)Session["App"]).PutCallData("PaymentType", ddlPaymentType.SelectedItem.Value);

            if (ecCheck)
            {
                ((DataAccess)Session["App"]).PutCallData("ECBankName", tbBankName.Text);
                ((DataAccess)Session["App"]).PutCallData("BankCity", tbBankCity.Text);
                ((DataAccess)Session["App"]).PutCallData("ECAccNumber", tbAccNum.Text);
                ((DataAccess)Session["App"]).PutCallData("ECRoutingNumber", tbRoutNum.Text);
                ((DataAccess)Session["App"]).PutCallData("ECCheckNumber", tbCheckNum.Text);
                ((DataAccess)Session["App"]).PutCallData("ECAccType", ddlAccType.SelectedItem.Text);
            }
            else
            {
                lblError.Text += "Invalid Bank Info<br/>";
            }
        }
        else
        {
            //lblError.Text += "Please select a payment method." + Environment.NewLine;
        }



        if (bCustValid)
        {
            if (ccCheck || ecCheck)
            {
                lblCustDataEntered.Visible = false;
                ddlProducts.Visible = true;
            }
            else
            {
                lblCustDataEntered.Visible = true;
                ddlProducts.Visible = false;
            }
        }
        else
        {
            lblCustDataEntered.Visible = true;
            ddlProducts.Visible = false;
        }

    }


    protected void ddlPaymentType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlPaymentType.SelectedValue == "CC")
        {
            trCCNumber.Visible = true;
            trCCType.Visible = true;
            trCCExpDate.Visible = true;
            trCCV.Visible = true;
            trECAccNum.Visible = false;
            trECBankName.Visible = false;
            trECCheckNum.Visible = false;
            trECRoutNum.Visible = false;
            trBankCity.Visible = false;
            trECAccType.Visible = false;
        }
        else if (ddlPaymentType.SelectedValue == "EC")
        {
            trCCNumber.Visible = false;
            trCCType.Visible = false;
            trCCExpDate.Visible = false;
            trCCV.Visible = false;
            trECAccNum.Visible = true;
            trECBankName.Visible = true;
            trBankCity.Visible = true;
            trECCheckNum.Visible = true;
            trECRoutNum.Visible = true;
            trECAccType.Visible = true;
        }
        else
        {
            trCCNumber.Visible = false;
            trCCType.Visible = false;
            trCCExpDate.Visible = false;
            trCCV.Visible = false;
            trECAccNum.Visible = false;
            trECBankName.Visible = false;
            trECCheckNum.Visible = false;
            trECRoutNum.Visible = false;
            trECAccType.Visible = false;
            trBankCity.Visible = false;
        }

    }

    protected void cbShipping_CheckedChanged(object sender, EventArgs e)
    {
        if (cbShipping.Checked)
        {
            trShipAddr.Visible = true;
            trShipAddr2.Visible = true;
            trShipCity.Visible = true;
            trShipState.Visible = true;
            trShipCountry.Visible = true;
            trShipZip.Visible = true;
            trShipLbl.Visible = true;
            trShipSearchZip.Visible = true;

        }
        else
        {
            trShipAddr.Visible = false;
            trShipAddr2.Visible = false;
            trShipCity.Visible = false;
            trShipState.Visible = false;
            trShipCountry.Visible = false;
            trShipZip.Visible = false;
            trShipLbl.Visible = false;
            trShipSearchZip.Visible = false;
        }
    }

    protected void btnSearchZip_Click(object sender, EventArgs e)
    {
        ValidateZip(tbZip.Text.ToUpper(), ddlCity, ddlState, ddlCountry);
    }

    protected void btnShipSearchZip_Click(object sender, EventArgs e)
    {
        ValidateZip(tbShipZip.Text.ToUpper(), ddlShipCity, ddlShipState, ddlShipCountry);
    }

    protected void ValidateZip(string strZip, DropDownList ddl_City, DropDownList ddl_State, DropDownList ddl_Country)
    {

        ddl_City.Items.Clear();
        ddl_State.Items.Clear();
        ddl_City.Enabled = true;

        if (System.Text.RegularExpressions.Regex.IsMatch(strZip.ToUpper(), @"(^\d{5}$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)"))
        {
            try
            {
                com.codebump.GeoPlaces g = new com.codebump.GeoPlaces();

                com.codebump.AuthenticationHeader authHeader = new com.codebump.AuthenticationHeader();
                authHeader.SessionID = "6JV2ZA4lgG1YRR+HG+JU27QWk9zI3rpRWY2iG2mzNPcdieEQXfQv0OUY0EZ+pOTxhwI1NCuF7b2oY+U/bozy0mhjFHmpaXvb";
                g.AuthenticationHeaderValue = authHeader;

                com.codebump.GeoPlaceDistance[] places = g.GetPlacesInside(strZip, "");

                for (int i = 0; i < places.Length; i++)
                {
                    com.codebump.GeoPlaceDistance place = places[i];
                    ListItem li = new ListItem(place.ToPlace, place.ToState + "," + place.ToPlace);
                    ddl_City.Items.Add(li);
                }

                ddl_State.Items.Add(ddl_City.SelectedItem.Value.Split(",".ToCharArray())[0]);

                //ddlCity.SelectedIndex = 0;

                if (System.Text.RegularExpressions.Regex.IsMatch(strZip.ToUpper(), @"(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)"))
                {
                    ddl_Country.SelectedValue = "CANADA";
                }
                else
                {
                    ddl_Country.SelectedValue = "USA";
                }

                if (ddl_City.Items.Count <= 0)
                {
                    ddl_City.Items.Add("No Cities Found");
                    ddl_City.Enabled = false;
                }
                else
                {
                    ddl_City.Items.Insert(0, "Select a City");
                    ddl_City.SelectedIndex = 0;
                }
            }
            catch
            {
                ddl_City.Items.Add("No Cities Found");
                ddl_City.Enabled = false;
            }
        }
        else
        {
            ddl_City.Items.Add("Invalid Zip");
            ddl_City.Enabled = false;
        }
    }

    public DataAccess.CardType GetCardType(string cardType)
    {
        switch (cardType)
        {
            case "A":
                return DataAccess.CardType.AmericanExpress;
            case "V":
                return DataAccess.CardType.Visa;
            case "D":
                return DataAccess.CardType.Discover;
            case "M":
                return DataAccess.CardType.MasterCard;
            default:
                return DataAccess.CardType.Visa;
        }
    }


    protected void Button2_Click(object sender, EventArgs e)
    {
        Panel3.Visible = !Panel3.Visible;
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        Label1.Visible = !Label1.Visible;
        ddlQty.Visible = !ddlQty.Visible;
    }
    protected void btnFAQ_Click(object sender, EventArgs e)
    {
        pnlFAQ.Visible = !pnlFAQ.Visible;
        pnlWizard.Visible = !pnlWizard.Visible;
    }

    public void SaveOriginalCallinfo(string uID)
    {
        biz.virtualacd.atl_app1.CallDetailGatewayService test = new biz.virtualacd.atl_app1.CallDetailGatewayService();
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        doc.LoadXml(test.getCallDetailByUniqueId("8b2cedb6c532cb63f689e9375374a576", uID));

        //assuming you have a field in the calldata table called "originalANI" and “originalDNIS”
        if (doc.SelectSingleNode("//ani") == null)
        {
            ((DataAccess)Session["App"]).PutCallData("clientANI", "");
            ((DataAccess)Session["App"]).PutCallData("clientDNIS", "");
            ((DataAccess)Session["App"]).CommitCallData();
        }
        else
        {
            ((DataAccess)Session["App"]).PutCallData("clientANI", doc.SelectSingleNode("//ani").InnerText);
            ((DataAccess)Session["App"]).PutCallData("clientDNIS", doc.SelectSingleNode("//dnis").InnerText);
            ((DataAccess)Session["App"]).CommitCallData();
        }
    }


    //   static string GetMd5Hash(MD5 md5Hash, string input)
    //{

    //    // Convert the input string to a byte array and compute the hash.
    //    byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));

    //    // Create a new Stringbuilder to collect the bytes
    //    // and create a string.
    //    StringBuilder sBuilder = new StringBuilder();

    //    // Loop through each byte of the hashed data 
    //    // and format each one as a hexadecimal string.
    //    for (int i = 0; i < data.Length; i++)
    //    {
    //        sBuilder.Append(data[i].ToString("x2"));
    //    }

    //    // Return the hexadecimal string.
    //    return sBuilder.ToString();
    //}
    // //  using (MD5 md5hash = MD5.Create())
    // //      {
    //   //        string hash = GetMD5Hash(md5hash, DateTime.UtcNow);
    //     //  }

    //public void PreAuth()
    //{

    //}


    protected void Button3_Click(object sender, EventArgs e)
    {
        Panel4.Visible = !Panel4.Visible;
    }

    public void PreAuth()
    {
        com.ebizcharge.payments.BankCardResponse bankresponse = new com.ebizcharge.payments.BankCardResponse();
        com.ebizcharge.payments.HashInput hashin = new com.ebizcharge.payments.HashInput();
        com.ebizcharge.payments.ChargeDetailInput chargein = new com.ebizcharge.payments.ChargeDetailInput();
        //com.ebizcharge.payments.CustDetailInput custin = new com.ebizcharge.payments.CustDetailInput();

        hashin.HashSeed = Convert.ToString(DateTime.Now.Ticks);
        hashin.HashType = "SHA1";
        hashin.Sourcekey = "fa9RY225E50Uq8kR0oVZvB34WbCHqL3u";
        hashin.PinHash = "7285";

        chargein.CreditCardNumber = "4111111111111111";
        chargein.EntryMode = "0";
        chargein.CardExpiration = "1213";
        chargein.CustomerNumber = "111111111111";
        chargein.Amount = 1;
        
        
        com.ebizcharge.payments.EBIZCHARGE_TRANSACTION_PROCESSINGSoap test3 = new com.ebizcharge.payments.EBIZCHARGE_TRANSACTION_PROCESSINGSoap();
       
        
    }

    protected void ddlProducts_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlProducts.SelectedItem.Text == "Choose One")
        {
            lblNoProduct.Visible = true;
        }
        else
        {
            lblNoProduct.Visible = false;
        }
        double SH = 0;

        if (ddlCountry.SelectedItem.Text == "CANADA")
        {
            SH = 8.99;
        }
        else
        {
            SH = 6.99;
        }

        switch (ddlProducts.SelectedValue)
        {
            case "1":
                lblAmount.Text = Convert.ToString(SH);
                break;
            case "2":
                lblAmount.Text = Convert.ToString(SH + 19.95);
                break;
            case "3":
                lblAmount.Text = Convert.ToString(SH + 19.95);
                break;
            case "4":
                lblAmount.Text = Convert.ToString(SH + 39.95);
                break;
            case "5":
                lblAmount.Text = Convert.ToString(SH + 39.95);
                break;
            case "6":
                lblAmount.Text = Convert.ToString(SH + 19.95 + 39.95);
                break;
            case "7":
                lblAmount.Text = Convert.ToString(SH + 59.9);
                break;
            case "8":
                lblAmount.Text = Convert.ToString(SH + 19.95 + 39.95);
                break;
            default:
                break;
        }
    }

    public void AddProducts()
    {
        switch (ddlProducts.SelectedValue)
        {
            case "1":
                ((DataAccess)Session["App"]).PutOrderItem(241, 1);
                break;
            case "2":
                ((DataAccess)Session["App"]).PutOrderItem(244, 1);
                break;
            case "3":
                ((DataAccess)Session["App"]).PutOrderItem(241, 1);
                ((DataAccess)Session["App"]).PutOrderItem(245, 1);
                break;
            case "4":
                ((DataAccess)Session["App"]).PutOrderItem(242, 1);
                break;
            case "5":
                ((DataAccess)Session["App"]).PutOrderItem(240, 1);
                break;
            case "6":
                ((DataAccess)Session["App"]).PutOrderItem(242, 1);
                ((DataAccess)Session["App"]).PutOrderItem(245, 1);
                break;
            case "7":
                ((DataAccess)Session["App"]).PutOrderItem(243, 1);
                break;
            case "8":
                ((DataAccess)Session["App"]).PutOrderItem(240, 1);
                ((DataAccess)Session["App"]).PutOrderItem(245, 1);
                break;
            default:
                break;
        }
    }
    protected void btnGeneralReb_Click(object sender, EventArgs e)
    {
        pnlSkepticalReb.Visible = false;
        pnlGeneralReb.Visible = !pnlGeneralReb.Visible;
    }
    protected void btnSkepticalReb_Click(object sender, EventArgs e)
    {
        pnlGeneralReb.Visible = false;
        pnlSkepticalReb.Visible = !pnlSkepticalReb.Visible;
    }
    protected void btnRebNoCont_Click(object sender, EventArgs e)
    {
        pnlRebNoCont.Visible = !pnlRebNoCont.Visible;
    }
    //protected void btnConfirmYesOk_Click(object sender, EventArgs e)
    //{
    //    lblConfirmYesOk.Visible = !lblConfirmYesOk.Visible;
    //}
    //protected void btnConfirmYesOk2_Click(object sender, EventArgs e)
    //{
    //    lblConfirmYesOk2.Visible = !lblConfirmYesOk2.Visible;
    //}
    protected void btnBilled_Click(object sender, EventArgs e)
    {
        pnlBillRebuttal.Visible = !pnlBillRebuttal.Visible;
    }
}